﻿using Furion.Logging;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GnpFine.Core.Logging;

public class DatabaseLoggingWriter_old : IDatabaseLoggingWriter
{
    private readonly IServiceScopeFactory _serviceScopeFactory;

    // 支持构造函数注入任何实例，会自动释放任何服务，比如注入 IRepository，或者 SqlSugarClient
    public DatabaseLoggingWriter_old(IServiceScopeFactory serviceScopeFactory)
    {
        _serviceScopeFactory = serviceScopeFactory;
    }
    public void Write(LogMessage logMsg, bool flush)
    {
        // 这里写你任何插入数据库的操作，无需 try catch

        using var serviceScope = _serviceScopeFactory.CreateScope();
        var logOpRep = serviceScope.ServiceProvider.GetService<SqlSugarRepository<SysLogOp>>();

        SysLogOp logtmp = new SysLogOp();
        logtmp.HttpMethod = "POST";
        logtmp.RequestUrl = "http://re";
        logtmp.ReturnResult = logMsg.Message;
        logtmp.Message = logMsg.Message;



        bool issuc = logOpRep.Insert(logtmp);

        if (issuc)
        {
            Console.WriteLine("pp");
        }




    }
}